﻿using Assets.Script.NetSystem.Services.HallService;
using LiteNetLib;
using SimpleTools.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using _2DGame_Preview_Server.Services.RoomAndBattle.Model;
using _2DGame_Preview_Server.Services.RoomAndBattle.RoomHall.Model;
using Assets.BattleSystem.EnemyConfigs;
using Newtonsoft.Json;
using Script.UiSystem;
using Script.UiSystem.Hall;
using UnityEngine;

namespace Assets.Script.NetSystem.Services.RoomAndBattle.HallService.Handler
{
    public class RoomsInfo : IHallHandler
    {
        public void Handler(HallClient hallClient, JsonData jsonData)
        {
            Debug.Log(jsonData.Json);

            Dictionary<int, RoomCore> dic = JsonConvert.DeserializeObject<Dictionary<int, RoomCore>>(jsonData.GetStr("dic"));
            
            List<RoomInfo> rooms = new List<RoomInfo>();
            foreach (var roomCore in dic.Values)
            {
                rooms.Add(roomCore.roomInfo);
            }
            
            GlobalCache.AddData("caseconfig", JsonConvert.DeserializeObject<CaseSpawnConfig>(jsonData.GetStr("caseconfig")));
            Debug.Log(GlobalCache.GetData("caseconfig"));

            HallController.Instance.InitRooms(rooms);
        }
    }
}
